package cn.flying.cloud.system.log.service.impl;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.flying.cloud.base.common.utils.Ft;
import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.system.log.entity.SysOperLog;
import cn.flying.cloud.system.log.mapper.SysOperLogMapper;
import cn.flying.cloud.system.log.service.SysOperLogService;

/**
 * 操作日志表 服务实现类
 *
 * @author admin
 * @since 2025-08-17 23:11:35
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements SysOperLogService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 查询总数
     *
     * @param param
     * @return
     */
    @Override
    public long countObj(SysOperLog param) {
        return this.count(getLambdaQueryWrapper(param));
    }

    /**
     * 分页查询操作日志表数据
     *
     * @param request
     * @return
     */
    @Override
    public PageResponse<SysOperLog> getPageList(PageRequest<SysOperLog> request) {
        SysOperLog param = request.getParam();
        LambdaQueryWrapper<SysOperLog> wrapper = getLambdaQueryWrapper(param);
        wrapper.orderByDesc(SysOperLog::getCreatedTime);
        Page<SysOperLog> page = this.page(new Page<>(request.getPageNum(), request.getPageSize()), wrapper);
        return new PageResponse<>(page.getTotal(), (int) page.getCurrent(), page.getRecords());
    }

    /**
     * 构建查询对象
     *
     * @param param
     * @return
     */
    private LambdaQueryWrapper<SysOperLog> getLambdaQueryWrapper(SysOperLog param) {
        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return wrapper;
    }

    /**
     * 列表查询操作日志表数据
     *
     * @param param
     * @return
     */
    @Override
    public List<SysOperLog> getList(SysOperLog param) {
        LambdaQueryWrapper<SysOperLog> wrapper = getLambdaQueryWrapper(param);
        // wrapper TODO
        return this.list(wrapper);
    }

    /**
     * 查询操作日志表详情数据
     *
     * @param param
     * @return
     */
    @Override
    public SysOperLog getOneObj(SysOperLog param) {
        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.getOne(wrapper);
    }

    /**
     * 根据Id查询操作日志表详情数据
     *
     * @param id
     * @return
     */
    @Override
    public SysOperLog getObjById(Serializable id) {
        return this.getById(id);
    }

    /**
     * 新增操作日志表数据
     *
     * @param param
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean createObj(SysOperLog param) {
        if (Ft.String.isBlank(param.getTenantId())) {
            param.setTenantId(Ft.Local.TenantId());
        }
        return this.save(param);
    }

    /**
     * 更新操作日志表数据
     *
     * @param param
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateObj(SysOperLog param) {
        return this.saveOrUpdate(param);
    }

    /**
     * 删除操作日志表数据
     *
     * @param param
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteObj(SysOperLog param) {
        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.remove(wrapper);
    }

    /**
     * 根据Id删除操作日志表数据
     *
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteById(Serializable id) {
        return this.removeById(id);
    }
}
